@using BlazorApp.Pages.Common.Html
@using BlazorApp.Pages.Common.Html.HTable
@using BlazorApp.Pages.Common.Metadata
@using BlazorApp.Utils
@using k8s.Models
@inherits BlazorApp.Pages.Common.PageBase

@if (Volume.ConfigMap != null)
{
    <BadgeRibbon Text="@Volume.Name" Placement="start" Color="#832">
        <TextTemplate>
            <span style="color:#DCDCDC">@Index</span>
            <Icon Type="hdd" Theme="outline"/>
            @Volume.Name
        </TextTemplate>
        <ChildContent>
            <Card Bordered>
                <HTable >
                    <HTableColumn Title=@L["Volume"] ExplainField="pod.spec.volumes.secret">
                        <RefView Ref="@TransferToRef(Volume)" FullView="true"></RefView>
                    </HTableColumn>
                    <PropertySimpleView Title=@L["Name"] ExplainField="pod.spec.volumes.configMap.name" Item="@Volume.ConfigMap.Name"></PropertySimpleView>
                    <PropertySimpleView Title=@L["DefaultMode"] ExplainField="pod.spec.volumes.configMap.defaultMode" Item="@Volume.ConfigMap.DefaultMode"></PropertySimpleView>
                    <PropertySimpleView Title=@L["Optional"] ExplainField="pod.spec.volumes.configMap.optional" Item="@Volume.ConfigMap.Optional"></PropertySimpleView>
                    @if (Volume.ConfigMap.Items != null)
                    {
                        @foreach (var ktp in Volume.ConfigMap.Items)
                        {
                            <HTableColumn Title=@L["ConfigMap"] ExplainField="pod.spec.volumes.configMap">
                                <Tag>@ktp.Key => @ktp.Path</Tag>
                                @if (ktp.Mode != null)
                                {
                                    <Tag>@ktp.Mode</Tag>
                                }
                            </HTableColumn>
                        }
                    }
                </HTable>

            </Card>
        </ChildContent>
    </BadgeRibbon>
}


@code {


    [Parameter] public V1Volume Volume { get; set; }

    [Parameter] public int Index { get; set; }

    [Parameter] public string Namespace { get; set; }

    private V1ObjectReference TransferToRef(V1Volume volume)
    {
        return KubeHelper.GetObjectRef("ConfigMap", Namespace, volume.ConfigMap.Name);
    }

}
